package com.x.crm.manage;


import com.x.crm.dao.CustomerShopDao;
import com.x.crm.dao.IntentionDao;
import com.x.crm.model.CustomerShop;
import com.x.crm.model.Intention;
import com.x.crm.util.Constant;
import com.x.framework.manage.BaseManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerShopManage extends BaseManage{


	@Autowired
	private IntentionDao intentionDao;



	@Autowired
	private CustomerShopDao customerShopDao;



	/**
	 * 客户分配后跟新意向
	 *
	 * @param customerShop
	 * @return
	 * @throws Exception
	 */
	public int updateCustomerShopAlloctInfo(CustomerShop customerShop ) throws Exception {
        Intention intention = new Intention();
        intention.setCustomerShopId(customerShop.getCustomerShopId());
		List<Intention> intentionList = intentionDao.selectIntentionInfoList(intention);
		if (intentionList != null &&  intentionList.size() > 0) {
			for(Intention model:intentionList){
				model.setFollowerId(customerShop.getFollowerId());
				model.setFollowerName(customerShop.getFollowerName());
				if(!model.getOpportunityState().equals(Constant.OPPORTUNITY_YGL)){
					model.setOpportunityState(Constant.OPPORTUNITY_YCL);
				}
				if (model.getIntentionState() == Constant.INTENTION_DFP){
					model.setIntentionState(Constant.INTENTION_DGJ);
				}
				this.update(model);
			}
		}
		return this.update(customerShop);
	}
	/**
	 * 客户释放跟新意向
	 * @param customerShop
	 * @return
	 * @throws Exception
	 */
	public int updateCustomerShopReleaseInfo(CustomerShop customerShop ) throws Exception {
		Intention intention = new Intention();
		intention.setCustomerShopId(customerShop.getCustomerShopId());
		intentionDao.updateReleaseIntentionInfo(intention);
		return customerShopDao.updateReleaseFollowInfo(customerShop);
	}





}
